import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_demo/entity/user.dart';
import 'package:flutter_demo/util/pref_util.dart';

class AppStore with ChangeNotifier {
  User _user = User();

  AppStore() {
    init();
  }

  init() async{
    _user = User.fromJson(json.decode(await PrefUtil.get('user')));
    if (_user == null) {
      _user = User();
    }
    notifyListeners();
  }

  User get user => _user;

  set user(User user) {
    if (user == null) {
      _user = User();
    } else {
      _user = user;
    }
    PrefUtil.setObject('user', _user);
    notifyListeners();
  }
}